<?php
if($this->ma == 1){
    echo '<script language="javascript" type="text/javascript">alert("快递添加(更新)成功！");location.href = "/admini/express/"; </script>';
}elseif($this->ma == 2){
    echo '<script language="javascript" type="text/javascript">alert("快递名称已存在,请更换名称！"); </script>';
}
?>
<script src="/admins/js/jquery.form.js" type="text/javascript"></script>
<form action="/admini/express/addexpress/" id="express" method="post">
<div class="">
    <div class="admin_nrtop">
        <div class="couriercompanycz">
            <div class="nui-toolbar-item">
                <div class="nui-btn ">
                    <a href="/admini/express/index" class="nui-btn-text"><span>&lt;&lt;</span>返回</a>
                </div>
            </div>                    
            <div class="nui-toolbar-item">
                <div class="nui-btn ">
                    <a href="javascript:;" name='save' class="nui-btn-text">保存添加</a>
                </div>
                <div class="nui-btn ">
                    <a href="javascript:;" name='reset' class="nui-btn-text">重置</a>
                </div>
            </div>  
        </div>
    </div>
    <div class="addbox">
      <div class="addtop">
            <h1>
                <?php
                    if($this->expressItem){
                        echo '更新快递(', $this->expressItem->Name .')';
                    }else{
                        echo '添加新快递';
                    }
                ?>
            </h1>
        </div>
        <div class="addtable">
            <table>
                <tr>
                    <td class="addl">快递名称：</td>
                    <td>
                        <div class="addinput">
                            <input type="hidden" id="id" name="id" value="<?php echo $this->expressItem ? $this->expressItem->Id : '' ?>" />
                            <input class="txtBxF" name="name" type="text" value="<?php echo $this->expressItem ? $this->expressItem->Name : '' ?>"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="addl">是否按体积：</td>
                    <td>
                        <div class="addradio">
                            
                            <label>
                                <input name="isVolume" type="radio" value="1" <?php echo ( $this->expressItem && $this->expressItem->isVolume == 1 ) || empty($this->expressItem) ? 'checked' : '' ?>>是
                            </label>
                            <label><input name="isVolume" type="radio" value="0" <?php echo $this->expressItem && $this->expressItem->isVolume == 0 ? 'checked' : '' ?>>否</label>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="addl">可走敏感项：</td>
                    <td>
                        <div class="addcheckbox">
                            <ul>
                            <?php foreach ($this->storeArrName as $key => $storeVal) { ?>
                            <?php 
                                if(in_array( $key, array(Application_Model_StoreItem::TYPE_Normal) )) {
                                    // , Application_Model_StoreItem::TYPE_Sensitive
                                    continue;
                                }
                            ?>
                                <li>
                                    <label>
                                        <input name="checkstore[]" type="checkbox" value="<?php echo $key;?>" <?php echo $this->expressItem && isset($this->arrtype[$key]) && $this->arrtype[$key] == true ? "checked" : "" ; ?>>&nbsp;<?php echo $storeVal[0];?>
                                    </label>
                                </li>
                            <?php }?>
                            </ul>
                        </div>
                    </td>
                </tr>
              <tr>
                    <td class="addl">运输时间：</td>
                    <td>
                      <div class="addtian">
                            <input class="txtBxF" name="minDay" type="text" datatype="float"  value="<?php echo $this->expressItem && isset($this->day[0]) ? $this->day[0] : '' ?>">
                            <i>至</i>
                            <input class="txtBxF" name="maxDay" type="text" datatype="float"  value="<?php echo $this->expressItem && isset($this->day[1]) ? $this->day[1] : '' ?>">
                            <i>天</i>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">是否要发票：</td>
                    <td>
                        <div class="addradio">
                            <label><input name="isInvoice" type="radio" value="1" <?php echo ( $this->expressItem && $this->expressItem->isInvoice == 1 ) || empty($this->expressItem) ? 'checked' : '' ?>>需要</label>
                            <label><input name="isInvoice" type="radio" value="0" <?php echo $this->expressItem && $this->expressItem->isInvoice == 0 ? 'checked' : '' ?>>不需要</label>
                        </div>
                    </td>
                </tr>
              <tr>
                    <td class="addl">快递logo：</td>
                    <td>
                        <div class="addfile">
                            <div class="addfilesc">

                                <div class="btn">
                                    <input id="fileupload" type="file" name="mypic" accept="image/*">
                                </div>
                                <div class="progress" style="display:none;">
                                    <span class="bar"></span><span class="percent">0%</span >
                                </div>
                                <div class="files"></div>
                                <div id="showimg"></div>

                            </div>
                            <div id="imgdiv" class="kdlogo">
                                <img id="imgShow" <?php echo $this->expressItem && $this->expressItem->logo ? " src='{$this->expressItem->logo}'" : ''; ?>>
                                <?php if($this->expressItem && !$this->expressItem->logo){ ?>
                                    无logo图
                                <?php } ?>
                                <input type='hidden' value='<?php echo $this->expressItem && $this->expressItem->logo ? $this->expressItem->logo : ''; ?>' id='imgpath' name='imgpath'>
                            </div>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">燃油费：</td>
                    <td>
                      <div class="addradio2">
                          <div class="radiol">
                                <label><input name="fuelSurcharge" type="radio" value="0" <?php echo !$this->expressItem || $this->expressItem->FuelSurcharge == 0 ? 'checked' : ''; ?>>无</label>
                            </div>
                          <div class="addradioinput">
                                <label><input name="fuelSurcharge" type="radio" value="1" <?php echo $this->expressItem && $this->expressItem->FuelSurcharge > 0 ? 'checked' : ''; ?>>有</label>
                                <div class="radioinput">
                                    <input class="txtBxF" datatype="float"  name="fuel" type="text" placeholder="费率" value="<?php echo $this->expressItem && $this->expressItem->FuelSurcharge  > 0 ? $this->expressItem->FuelSurcharge *100 : ''; ?>" <?php echo !$this->expressItem || $this->expressItem->FuelSurcharge == 0 ? 'disabled' : ''; ?>/>
                                    <i>%</i>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">偏远费：</td>
                    <td>
                      <div class="addradio2">
                          <div class="radiol">
                                <label>
                                    <input name="isRemoteFee" type="radio" value="0" <?php echo !$this->expressItem || $this->expressItem->IsRemoteFee == 0 || $this->expressItem->RemoteFee == 0 ? 'checked' : ''; ?>>无
                                </label>
                            </div>
                          <div class="addradioinput">
                                <label><input name="isRemoteFee" type="radio" value="1" <?php echo $this->expressItem && $this->expressItem->IsRemoteFee == 1 && $this->expressItem->RemoteFee > 0 ? 'checked' : ''; ?>>有</label>
                                <div class="radioinput">
                                  <input class="txtBxF" datatype="float"  name="remoteFee" type="text" value="<?php echo $this->expressItem && $this->expressItem->IsRemoteFee == 1 && $this->expressItem->RemoteFee > 0 ? $this->expressItem->RemoteFee : ''; ?>" placeholder="金额" <?php echo !$this->expressItem || $this->expressItem->IsRemoteFee == 0 || $this->expressItem->RemoteFee == 0 ? 'disabled' : ''; ?>/>
                                  <i>元+燃油</i>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">其他费用：</td>
                    <td>
                      <div class="addradio2">
                          <div class="radiol">
                                <label><input name="isOthers" type="radio" value="0" <?php echo !$this->expressItem || $this->expressItem->OthersFee == 0 ? 'checked' : ''; ?>>无</label>
                            </div>
                          <div class="addradioinput">
                                <label><input name="isOthers" type="radio" value="1" <?php echo $this->expressItem && $this->expressItem->OthersFee > 0 ? 'checked' : ''; ?>>有</label>
                                <div class="radioinput">
                                  <input class="txtBxF" datatype="float"  name="othersFee" type="text" value="<?php echo $this->expressItem && $this->expressItem->OthersFee > 0 ? $this->expressItem->OthersFee : ''; ?>" placeholder="金额" <?php echo !$this->expressItem || $this->expressItem->OthersFee == 0 ? 'disabled' : ''; ?>/><i>元</i>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">跟踪所属：</td>
                    <td>
                        <div class="addradio">
                            <select name="trackType">
                                <option value="1" <?php echo !$this->expressItem || $this->expressItem->TrackType == 1 ? ' selected="selected"' : ''; ?>>快递100</option>
                                <option value="2" <?php echo !$this->expressItem || $this->expressItem->TrackType == 2 ? ' selected="selected"' : ''; ?>>悠奇手工</option>
                                <option value="3" <?php echo !$this->expressItem || $this->expressItem->TrackType == 3 ? ' selected="selected"' : ''; ?>>第三方网站</option>
                                <option value="4" <?php echo !$this->expressItem || $this->expressItem->TrackType == 4 ? ' selected="selected"' : ''; ?>>官网</option>
                                <option value="5" <?php echo !$this->expressItem || $this->expressItem->TrackType == 5 ? ' selected="selected"' : ''; ?>>混合</option>
                                <option value="6" <?php echo !$this->expressItem || $this->expressItem->TrackType == 6 ? ' selected="selected"' : ''; ?>>无</option>
                            </select>
                        </div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">官网地址：</td>
                    <td>
                      <div class="addinput"><input name="webUrl" class="txtBxF" type="text" value="<?php echo $this->expressItem ? $this->expressItem->WebUrl : '' ?>"/></div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">官网追踪地址：</td>
                    <td>
                      <div class="addinput"><input name="trackUrl" class="txtBxF" type="text" value="<?php echo $this->expressItem ? $this->expressItem->TrackUrl : '' ?>"/></div>
                    </td>
                </tr>
              <tr>
                  <td class="addl">快递介绍地址：</td>
                    <td>
                      <div class="addinput"><input name="helpUrl" class="txtBxF" type="text" value="<?php echo $this->expressItem ? $this->expressItem->HelpUrl : '' ?>"/></div>
                    </td>
                </tr>
            <tr>
              <td class="addl">物流code：</td>
                <td>
                  <div class="addinput"><input name="code" class="txtBxF" type="text" value="<?php echo $this->expressItem ? $this->expressItem->Code : '' ?>"/></div>
                </td>
            </tr>
            </table>
        </div>
    </div>
    <div class="addbar">
        <ul>
            <li><span class="ccbotton"  id="save" name='save'>保存添加</span></li>
            <li><span class="ccbotton2" id="reset" name='reset'>重置</span></li>
        </ul>
    </div>
</div>
</form>
<script type="text/javascript">
    $(function(){
        //保存添加
        $('[name=save]').click(function(){
            var name = $.trim($("[name=name]").val());
            if(name == ''){
                alert("快递名称不能为空！");
                return false;
            }
            $("#express").submit();
        })

        //重置
        $('[name=reset]').click(function(){
            location.reload();
        })

        $('[name=fuelSurcharge]').click(function(){
            var val = $(this).val();
            if(val == 0){
                $('[name=fuel]').attr('disabled', 'true');
                $('[name=fuel]').val('');
            }else{
                $('[name=fuel]').removeAttr('disabled');
            }
        })
        $('[name=isRemoteFee]').click(function(){
            var val = $(this).val();
            if(val == 0){
                $('[name=remoteFee]').attr('disabled', 'true');
                $('[name=remoteFee]').val('');
            }else{
                $('[name=remoteFee]').removeAttr('disabled');
            }
        })
        $('[name=isOthers]').click(function(){
            var val = $(this).val();
            if(val == 0){
                $('[name=othersFee]').attr('disabled', 'true');
                $('[name=othersFee]').val('');
            }else{
                $('[name=othersFee]').removeAttr('disabled');
            }
        })
    })
</script>
<script type="text/javascript">
$(function () {
    var bar = $('.bar');
    var percent = $('.percent');
    var showimg = $('#showimg');
    var progress = $(".progress");
    var files = $(".files");
    var btn = $(".btn span");
    $("#fileupload").wrap("<form id='myupload' action='/admini/ajax/upimg' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
        $("#myupload").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
                showimg.empty();
                progress.show();
                var percentVal = '0%';
                bar.width(percentVal);
                percent.html(percentVal);
                btn.html("上传中...");
            },
            uploadProgress: function(event, position, total, percentComplete) {
                var percentVal = percentComplete + '%';
                bar.width(percentVal);
                percent.html(percentVal);
            },
            success: function(data) {
                // files.html("<b>"+data.name+"("+data.size+"k)</b> <span class='delimg' rel='"+data.pic+"'>删除</span>");
                files.html("<b>"+data.name+"("+data.size+"k)</b>");
                var img = "http://cdn.uuch.com/expresslogo/"+data.pic;
                $('#imgShow').attr('src', img);
                $('#imgpath').val(img);
                btn.html("添加附件");
            },
            error:function(xhr){
                btn.html("上传失败");
                bar.width('0')
                files.html(xhr.responseText);
            }
        });
    });
    
    // $(".delimg").live('click',function(){
    //     var pic = $(this).attr("rel");
    //     $.post("action.php?act=delimg",{imagename:pic},function(msg){
    //         if(msg==1){
    //             files.html("删除成功.");
    //             showimg.empty();
    //             progress.hide();
    //         }else{
    //             alert(msg);
    //         }
    //     });
    // });
});
</script>